package com.recommend.recommendkeyword.service.impl;

import com.recommend.recommendkeyword.entity.Keywords;
import com.recommend.recommendkeyword.entity.RecommendKeyword;
import com.recommend.recommendkeyword.mapper.KeyWordsMapper;
import com.recommend.recommendkeyword.mapper.RecommendKeywordMapper;
import com.recommend.recommendkeyword.mapper.SearchHistoryMapper;
import com.recommend.recommendkeyword.service.RankingService;
import com.recommend.recommendkeyword.vo.OccurrenceCountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RankingServiceImpl implements RankingService {
    @Autowired
    SearchHistoryMapper searchHistoryMapper;
    @Autowired
    KeyWordsMapper keyWordsMapper;
    /**
     * 获取系统热词搜索排行榜
     */
    public List<Keywords> systemRanking() {
        List<OccurrenceCountVO> occurrenceCountVOList = searchHistoryMapper.getKeywordsCount();
        List<Keywords> keywordsList = new ArrayList<>();
        for (OccurrenceCountVO occurrenceCountVO : occurrenceCountVOList) {
            keywordsList.add(keyWordsMapper.getKeywordById(occurrenceCountVO.getKeywordId()));
        }
        return keywordsList;
    }

        /**
         * 获取个人热词搜索排行榜
         */
        public List<Keywords> userRanking(int userId){
            List<OccurrenceCountVO> occurrenceCountVOList = searchHistoryMapper.getUserWordsCount(userId);
            List<Keywords> keywordsList = new ArrayList<>();
            for(OccurrenceCountVO occurrenceCountVO: occurrenceCountVOList){
                keywordsList.add(keyWordsMapper.getKeywordById(occurrenceCountVO.getKeywordId()));
            }
            return keywordsList;
        }
}
